var twbOrderDetailVm = new Vue({
	el:'#twbOrderDetailApp',
	data: {
        title: null,
        //表单对齐方式
        labelPosition: 'right',
        //分配列表
        erpOrderProductionList:[],
        erpOrder: {orderNo:'',memberName:'',shipName:'',orderCreatetime:'',tel:'',productionStatus:'',shipStatus:'',productionRequest:''},
        //订单状态:
        productionStatusEnum: [{value:'',label:'订单状态'},{value: '7', label: '新开单'}, {value: '3', label: '生产中'}, {
            value: '4', label: '生产完成'}, {value: '6', label: '已完成'}],
        //订单类型
        orderSourceEnum: [],
        //商品明细列表
        orderItemDetailData: [],
        //商品修改
        startItemEdit: false,
        //定义type;用于跳回原来页面
        type:1,
    },
	methods: {
        loadData: function (dataParams) {
           this.erpOrder.orderNo= dataParams.orderNo;
           this.type=dataParams.type;
           if(isBlank(this.erpOrder.orderNo)){
               alert("获取订单信息失败，请刷新页面重新操作!");
               return;
           }
            this.getInfo();
        },
		getInfo: function(orderNo){
            var self=this;
            var orderNo=self.erpOrder.orderNo;
			$.get(baseURL + "twbOrder/erporder/info/"+orderNo, function(r){
                self.erpOrder = r.erpOrder;
                self.erpOrder.shipMobile=isBlank(self.erpOrder.shipMobile)?self.erpOrder.shipTel:self.erpOrder.shipMobile;
                self.orderRemarksData=r.orderRemarksData;
                self.erpOrderProductionList=r.erpOrderProductionList;
                //格式化数据twbOrderDetailVm.e
                var productionStatus= self.erpOrder.productionStatus;
                switch (productionStatus){
                case 1: self.erpOrder.productionStatus='待审核';break;
                case 2: self.erpOrder.productionStatus= '待分配';break;
                case 3: self.erpOrder.productionStatus= '生产中';break;
                case 4: self.erpOrder.productionStatus= '生产完成';break;
                case 5:	self.erpOrder.productionStatus='已发货';break;
                case 6: self.erpOrder.productionStatus= '已完成';break;
                case 7: self.erpOrder.productionStatus= '新开单' ;break;
                }
                var shipStatus= self.erpOrder.shipStatus;
                switch (shipStatus){
                    case 0: self.erpOrder.shipStatus='未发货';break;
                    case 1: self.erpOrder.shipStatus ='已发货';break;
                    case 2: self.erpOrder.shipStatus ='部分发货';break;
                }
                var payStatus=self.erpOrder.payStatus;
                switch (payStatus){
                    case 0: self.erpOrder.payStatus='未支付';break;
                    case 1: self.erpOrder.payStatus ='已支付';break;
                    case 3: self.erpOrder.payStatus ='部分支付';break;
                }
                self.recordItemData=JSON.parse(JSON.stringify(r.orderItemDetailData));
                self.orderItemDetailData=r.orderItemDetailData;
            });
		},
		reload: function (event) {
            if(this.type==1){
                window.parent.vm.zyRouter({
                    url:'modules/order/twbOrder.html',
                    name:'订单列表',
                    blank: true,
                    closeBlank: true,
                    vmName:'twbOrderVm',
                    params:{},
                });
            }else{
                window.parent.vm.zyRouter({
                    url:'modules/order/twbMonthOrder.html',
                    name:'月结订单',
                    blank: true,
                    closeBlank: true,
                    vmName:'twbMonthOrderVm',
                    params:{},
                });
            }
		},
        //添加供应商
        suppFormShow:function (row) {
            window.SupplierVm.loadData(row)
        },
        //改变总价同时单价也进行修改
        changeItemPrice:function(row){
            row.price=(row.amount/row.nums).toFixed(3);
        },
        //保存订单
        save:function () {
            var self=this;
            self.startItemEdit=false;
        },
        /* 分配选项删除 */
        delAllotItem: function (row) {
            this.$confirm('此操作将删除分配信息, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                callback: function (f) {
                    if (f == 'confirm'){
                        var productionId = row.productionId;
                        var orderNo = row.orderNo;
                        $.ajax({
                            type: "POST",
                            url: baseURL + "twbOrder/erporder/twbdeleteAllotItem?productionId=" + productionId + "&orderId=" + orderNo,
                            contentType: "application/json",
                            success: function(r){
                                if(r.code == 0){
                                    twbOrderDetailVm.getInfo(twbOrderDetailVm.erpOrder.orderNo);
                                }else{
                                    alert(r.msg);
                                }
                            }
                        });
                    }
                }
            })
        },
    }
});